﻿using System;
using System.Windows.Forms;

// SkypeScreenSaver, Copyright Mirosław M. Mączka.  All Rights Reserved. This code released under the terms of the Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.)

namespace SkypeScreenSaver
{
    static class Program
    {
        public enum SSMode { Normal, Configuration, Preview, Password };
        public static SSMode ssMode;
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            ssMode = SSMode.Normal;
            // First command-line param is the exe name, second param is the mode
            if (args.Length >= 1)
            {
                if (args[0].IndexOf("/c", StringComparison.CurrentCultureIgnoreCase) >= 0)// Configuration mode
                {
                    ssMode = SSMode.Configuration;
                    return;
                }
                else if (args[0].IndexOf("/a", StringComparison.CurrentCultureIgnoreCase) >= 0)// Password mode
                {
                    ssMode = SSMode.Password;
                    return;
                }
                else if (0 == string.Compare(args[0],"/p", true))// Preview mode
                {
                    ssMode = SSMode.Preview;
                    // Handle to preview dialog box is next command-line param
                    uint ui = 0;
                    if ((args.Length > 1) && uint.TryParse(args[1], out ui))
                    {
                        FormPreview.previewHwnd = (IntPtr)ui;
                    }
                    else
                    {
                        FormPreview.previewHwnd = IntPtr.Zero;
                    }
                }
                // "/s"
            }
            //
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //
            if (SSMode.Preview == ssMode)
            {
                FormPreview f = new FormPreview();
                f.ShowDialog();
                Application.Run();
            }
            else
            {
                Application.Run(new Form1());
            }
        }
    }
}
